package com.hmall.gateway.filters;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 自定义过滤器
 */
@Component
public class MyGlobalfilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //TODO模拟登录校验
        ServerHttpRequest request = exchange.getRequest();
        System.out.println(request.getHeaders());
        return chain.filter(exchange);  //放行
    }

    /**
     * 设置自定义过滤器的优先级
     * NettyRoutingFilter的优先级最低
     * @return
     */
    @Override
    public int getOrder() {
        return 1;
    }
}
